package com.example.demo.commom;

import lombok.Data;

import java.security.Signature;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-03-31
 * Time:16:10
 */
@Data
public class AjaxResult {
    //状态码

    private Integer code;


    //状态码描述信息
    private String msg;
    //返回数据

    private Object data;

    /*
    操作成功返回结果
     */
    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMsg("");
        ajaxResult.setData(data);
        return ajaxResult;
    }
    public static AjaxResult success(Integer code,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg("");
        ajaxResult.setData(data);
        return ajaxResult;
    }
    public static AjaxResult success(String msg,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }
    public static AjaxResult success(Integer code,String msg,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }
    /*
    失败返回
     */
    public static AjaxResult fail(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(-1);
        ajaxResult.setMsg("");
        ajaxResult.setData(data);
        return ajaxResult;
    }
    public static AjaxResult fail(String msg,Integer code) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(null);
        return ajaxResult;
    }
    public static AjaxResult fail(Integer code,String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(null);
        return ajaxResult;
    }
}
